import React, { useState, useEffect } from 'react';
import { PageContainer } from '@ant-design/pro-layout';
import ArchivesInfo from './ArchivesInfo';
import ServiceRecord from './ServiceRecord';
import { getPatientArchiveDetail } from '@/services/order/api';
import { isNull, showMsg } from '@/utils/utils';
import { history } from 'umi'
import './style.less';
import BreadcrumbDept from '@/components/BreadcrumbDept';
interface DetailProps {
  location?: any;
}

const Detail: React.FC<DetailProps> = (props) => {
  const { location } = props;
  const { query } = location;
  const { order_id, actId } = query;

  const [detail, setDetail] = useState<ORDERAPI.ArchiveInfo>({});
  const [showPrint, setShowPrint] = useState<boolean>(true);

  // 档案详情
  const fetchPatientArchiveDetail = async () => {
    try {
      const data: ORDERAPI.ArchiveInfo = await getPatientArchiveDetail(order_id, actId);
      setDetail(data);
    } catch (error) {
      showMsg(error?.data?.errmsg);
    }
  }

  useEffect(() => {
    if (order_id) {
      fetchPatientArchiveDetail();
    }
  }, [order_id]);

  const onReload = () => {
    fetchPatientArchiveDetail();
  }

  return (
    <PageContainer title="患者服务档案" extra={[
      <BreadcrumbDept />
     ]} breadcrumb={{}} onBack={() => isNull(actId) ? history.push({
      pathname: '/order/worker',
      query: {
        from: 'detail',
        order_id,
      }
    }) : history.goBack()}>
      <ArchivesInfo  
        order_id={order_id} 
        detail={detail} 
        onReload={onReload} />

      <ServiceRecord 
        order_id={order_id} 
        setShowPrint={setShowPrint}
        onReload={onReload}
        detail={detail} />
    </PageContainer>
  );
};
export default Detail;
